var app = getApp();

Page({
  data: {
    currentTab: 0,
    publishExpresses: [],
    acceptExpresses: []
  },
  onLoad() {
  },
  onShow() {
    this.setData({
      currentTab: 0,
      publishExpresses: [],
      acceptExpresses: []
    })
    this.publishExpressList()
    this.acceptExpressList()
  },
  changeOrder(e) {
    this.setData({
      currentTab: e.detail.current
    })
    if(this.data.currentTab == 0){
      this.publishExpressList()
    }else if(this.data.currentTab == 1){
      this.acceptExpressList()
    }
  },
  switchNav(e) {
    this.setData({
      currentTab: e.currentTarget.dataset.current
    })
    if(this.data.currentTab == 0){
      this.publishExpressList()
    }else if(this.data.currentTab == 1){
      this.acceptExpressList()
    }
  },
  publishDetail(e) {
    dd.navigateTo({
      url: "/pages/order/orderDetail/orderDetail?expressId=" + e.currentTarget.id + "&currentTab=" + this.data.currentTab
    })
  },
  acceptDetail(e) {
    dd.navigateTo({
      url: "/pages/order/orderDetail/orderDetail?expressId=" + e.currentTarget.id + "&currentTab=" + this.data.currentTab
    })
  },
  publishExpressList() {
    let self = this
    dd.getStorage({
      key: 'userInfo',
      success: function(res) {
        console.log('获取成功：' + res.data.userId);
        dd.httpRequest({
          url: app.globalData.url + '/express/publish/list',
          data: {
            publishId: res.data.userId
          },
          dataType: 'json',
          success: (res) => {
            self.setData({
              publishExpresses: res.data.data
            })
          },
          fail: (res) => {
            console.log("httpRequestFail---", res)
            dd.alert({ content: JSON.stringify(res) });
          },
          complete: (res) => {
            dd.hideLoading();
          }
        });
      },
      fail: function(res){
        dd.alert({content: res.errorMessage});
      }
    });
  },
  acceptExpressList() {
    let self = this
    dd.getStorage({
      key: 'userInfo',
      success: function(res) {
        console.log('获取成功：' + res.data.userId);
        dd.httpRequest({
          url: app.globalData.url + '/express/accept/list',
          data: {
            acceptId: res.data.userId
          },
          dataType: 'json',
          success: (res) => {
            self.setData({
              acceptExpresses: res.data.data
            })
          },
          fail: (res) => {
            console.log("httpRequestFail---", res)
            dd.alert({ content: JSON.stringify(res) });
          },
          complete: (res) => {
            dd.hideLoading();
          }
        });
      },
      fail: function(res){
        dd.alert({content: res.errorMessage});
      }
    });
  }
});
